home *** CD-ROM | disk | FTP | other *** search
- Path: news.infi.net!usenet
- From: Scott Hightower <hightowr@lex.infi.net>
- Newsgroups: comp.lang.c++
- Subject: Re: int::~int()
- Date: Tue, 16 Apr 1996 00:47:19 -0400
- Organization: InfiNet
- Message-ID: <31732657.5795@lex.infi.net>
- References: <317083F7.116E@public.sta.net.cn> <marnoldDpuDu9.D7s@netcom.com>
- NNTP-Posting-Host: h-admission.lex.infi.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01Gold (Win95; I)
-
- Matt Arnold wrote:
- >
- > Xu Yifeng <jafd@public.sta.net.cn> writes:
- >
- > >Hi everybody,
- >
- > >can your compiler compile following program?
- >
- > >//------------------------
- > >void main()
- > >{
- > > int i = 0;
- >
- > > i.int::~int();
- > >}
- > >//------------------------
- >
- > >is it a legal C++ program?
- >
- > It's supposed to be, but most C++ compiler's will not compile it.
- >
- > In fact, this exact sitution is encountered in the Standard Template
- > Library (STL), which contains the following template function...
- >
- > template <class T>
- > inline void destroy(T* pointer) {
- > pointer->~T();
- > }
- >
- > ...which is supposed to be used to destroy anything, including an
- > instance of an int, just like your sample code wants to.
- >
- > To make STL work with current compilers, you'll find it also contains
- > work-around versions of destroy(). There's one specifically for int,
- > and it looks like this...
- >
- > inline void destroy(int*) {}
- >
- > ...which is what the template version is supposed to do; nothing. STL
- > contains about 50 or so of these specific versions of destroy() (for
- > ints, chars, floats, etc.).
- >
- > You sample code is legal as far as the language goes, but probably
- > not as far as your compiler is concerned. Mine, Borland C++ 4.52,
- > will not compile it either. However, I think Borland C++ 5.0 will.
- >
- > Regards,
- > -------------------------------------------------------------------------
- > Matt Arnold | | ||| | |||| | | | || ||
- > marnold@netcom.com | | ||| | |||| | | | || ||
- > Boston, MA | 0 | ||| | |||| | | | || ||
- > 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- > C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- > -------------------------------------------------------------------------
- BC++ 5.0 did not like it, either.
-
-